/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package pfc.generacion;

import java.io.File;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.apache.commons.io.FileUtils;
import org.apache.ddlutils.model.Database;

import pfc.comun.Proyecto;
import pfc.modelocg.CGModel;
import pfc.modeloer.ERModel;

/**
 *
 * @author xandru
 */
public class Application {
    private final String _name;
    private final File _path;

    private Database _dbmodel;
    private ERModel _ermodel;
    private CGModel _cgmodel;

    public Application(File file) {
        this._path = file;
        this._name = file.getName();
    }

    public String getName() {
        return _name;
    }

    public File getPath() {
        return _path;
    }



    public void generate(Proyecto pro, Database db, ERModel er, CGModel cg) {
        GeneradorDTO genDTO = new GeneradorDTO(pro, db, er, cg);
        GeneradorDAO genDAO = new GeneradorDAO(pro, db, er, cg);
        GeneradorWEB genWEB = new GeneradorWEB(pro,db,er,cg);
        GeneradorValidacion genVal = new GeneradorValidacion(pro,db,er,cg);
        GeneradorPKGenerator genPK= new GeneradorPKGenerator(pro,db,er,cg);

        this._dbmodel = db;
        this._ermodel = er;
        this._cgmodel = cg;

        File srcPath = new File (this._path + File.separator + pro.getSrcFolderName());
        File buildPath = new File (this._path + File.separator + pro.getBuildFolderName());
        File distPath = new File (this._path + File.separator + pro.getDistFolderName());
        File webPath =  new File (this._path + File.separator + pro.getWebFolderName());

        try {
            FileUtils.forceMkdir(srcPath);
            FileUtils.forceMkdir(buildPath);
            FileUtils.forceMkdir(distPath);
            FileUtils.forceMkdir(webPath);
        } catch (IOException ex) {
            Logger.getLogger(Application.class.getName()).log(Level.SEVERE, null, ex);
        }

        genDTO.generarDTOs(srcPath);
        genDAO.generarDAOs(srcPath);
        genVal.generar(srcPath);
        genWEB.generarWEB(this._path);
        genPK.generar(srcPath);

        GeneradorAntMakefile ag = new GeneradorAntMakefile(pro,this._path.getPath());
        ag.generarAntMakeFile(this._name);

    }

    private void generarAntMakeFile(Proyecto pro) {
        
       
    }

    
}
